using UnityEngine;
using UnityEngine.UI;

public class ScreenDamage : MonoBehaviour
{
	public Image DamageSprite;

	public float FadeSpeed = 15f;

	private float alpha;

	private byte latestHP;

	private void Start()
	{
	}

	public void GetHit(float duration)
	{
		alpha = duration;
	}

	private void Update()
	{
		if (UnitZ.playerManager.PlayingCharacter == null || DamageSprite == null)
		{
			return;
		}
		if (UnitZ.playerManager.PlayingCharacter.HP != latestHP)
		{
			if (UnitZ.playerManager.PlayingCharacter.HP < latestHP)
			{
				GetHit(1f);
			}
			latestHP = UnitZ.playerManager.PlayingCharacter.HP;
		}
		alpha = Mathf.Lerp(alpha, 0f, FadeSpeed * Time.deltaTime);
		Image damageSprite = DamageSprite;
		Color color = DamageSprite.color;
		float r = color.r;
		Color color2 = DamageSprite.color;
		float g = color2.g;
		Color color3 = DamageSprite.color;
		damageSprite.color = new Color(r, g, color3.b, alpha);
	}
}
